<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 3.9.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"monocy.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":"valine","storage":true,"lazyload":true,"nav":null,"activeClass":"valine"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":false,"top_n_per_article":5,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言临近春节，很多人又考虑换工作了，考虑到还有一年多的工作的时间，提前总结总结也是不错的，这里就记录一下最近翻到了以及先前自己总结的一些问题，为之后的复习做准备。">
<meta name="keywords" content="面试题">
<meta property="og:type" content="article">
<meta property="og:title" content="前端面试题大全">
<meta property="og:url" content="https://monocy.gitee.io/2020/01/27/前端面试题大全/index.html">
<meta property="og:site_name" content="沐光">
<meta property="og:description" content="前言临近春节，很多人又考虑换工作了，考虑到还有一年多的工作的时间，提前总结总结也是不错的，这里就记录一下最近翻到了以及先前自己总结的一些问题，为之后的复习做准备。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2022-07-26T13:14:49.487Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="前端面试题大全">
<meta name="twitter:description" content="前言临近春节，很多人又考虑换工作了，考虑到还有一年多的工作的时间，提前总结总结也是不错的，这里就记录一下最近翻到了以及先前自己总结的一些问题，为之后的复习做准备。">

<link rel="canonical" href="https://monocy.gitee.io/2020/01/27/前端面试题大全/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>前端面试题大全 | 沐光</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">沐光</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">记录在前端之路的点点滴滴</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">15</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">61</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="reading-progress-bar"></div>

  <a href="https://github.com/kazehaiya" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://monocy.gitee.io/2020/01/27/前端面试题大全/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="蔡胤">
      <meta itemprop="description" content="Just do IT!">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="沐光">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          前端面试题大全
        </h1>

        <div class="post-meta">
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2022-07-26 21:14:49" itemprop="dateModified" datetime="2022-07-26T21:14:49+08:00">2022-07-26</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/面试题/" itemprop="url" rel="index"><span itemprop="name">面试题</span></a>
                </span>
            </span>

          
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Valine：</span>
    
    <a title="valine" href="/2020/01/27/前端面试题大全/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2020/01/27/前端面试题大全/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.7k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>2 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h3 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h3><p>临近春节，很多人又考虑换工作了，考虑到还有一年多的工作的时间，提前总结总结也是不错的，这里就记录一下最近翻到了以及先前自己总结的一些问题，为之后的复习做准备。</p>
<a id="more"></a>
<h3 id="HTML-篇"><a href="#HTML-篇" class="headerlink" title="HTML 篇"></a>HTML 篇</h3><h4 id="H5-有哪些新特性"><a href="#H5-有哪些新特性" class="headerlink" title="H5 有哪些新特性"></a>H5 有哪些新特性</h4><ul>
<li>语义化标签（header、footer、nav、aside、article、section 等）</li>
<li>增强表单（<a href="https://www.jianshu.com/p/d8b4c4055adc" target="_blank" rel="noopener">传送门</a>）</li>
<li>本地存储</li>
<li>多媒体元素标签： vedio 与 audio</li>
<li>新增地理定位方法</li>
<li>canvas 画布</li>
<li>拖放事件</li>
<li>webWorker</li>
<li>webSocket</li>
</ul>
<h4 id="webStorage-和-Cookie-的区别以及各自的优缺点"><a href="#webStorage-和-Cookie-的区别以及各自的优缺点" class="headerlink" title="webStorage 和 Cookie 的区别以及各自的优缺点"></a>webStorage 和 Cookie 的区别以及各自的优缺点</h4><table>
<thead>
<tr>
<th>特性</th>
<th>cookie</th>
<th>localStorage</th>
<th>sessionStorage</th>
</tr>
</thead>
<tbody>
<tr>
<td>数据生命周期</td>
<td>一般由服务器生成，可以设置过期时间</td>
<td>除非被清理，否则一直存在</td>
<td>页面关闭就清理</td>
</tr>
<tr>
<td>数据存储大小</td>
<td>4K</td>
<td>5M</td>
<td>5M</td>
</tr>
<tr>
<td>与服务端通信</td>
<td>每次都会携带在 header 中，对于请求性能影响</td>
<td>不参与</td>
<td>不参与</td>
</tr>
</tbody>
</table>
<blockquote>
<p>从上表可以看到，cookie 已经不建议用于存储。如果没有大量数据存储需求的话，可以使用 localStorage 和 sessionStorage 。对于不怎么改变的数据尽量使用 localStorage 存储，否则可以用 sessionStorage 存储。</p>
</blockquote>
<h4 id="svg-与-canvas"><a href="#svg-与-canvas" class="headerlink" title="svg 与 canvas"></a>svg 与 canvas</h4><table>
<thead>
<tr>
<th>svg</th>
<th>canvas</th>
</tr>
</thead>
<tbody>
<tr>
<td>svg 是一种使用 xml 描述 2D 图形的语言，<strong>矢量图</strong></td>
<td>canvas 通过 javascript 来绘制 2D 图形，<strong>标量图</strong></td>
</tr>
<tr>
<td>svg 基于 xml，这意味着 svg DOM 中的每个元素都是可用的，您可以为某个元素附加 javascript 事件处理器</td>
<td>canvas 是逐像素进行渲染的。在 canvas 中，一旦图形被绘制完成，它就不会继续得到浏览器的关注。如果其位置发生变化，那么整个场景也需要重新绘制，包括任何或许已被图形覆盖的对象</td>
</tr>
</tbody>
</table>
<h4 id="移动端页面适配方案"><a href="#移动端页面适配方案" class="headerlink" title="移动端页面适配方案"></a>移动端页面适配方案</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="actionscript">  <span class="comment">// 获取缩放大小</span></span></span><br><span class="line"><span class="javascript">  <span class="keyword">var</span> scale = <span class="number">1</span> / <span class="built_in">window</span>.devicePixelRatio;</span></span><br><span class="line"><span class="actionscript">  <span class="comment">// content 配置默认缩放大小，不允许缩放</span></span></span><br><span class="line"><span class="actionscript">  <span class="keyword">var</span> content =</span></span><br><span class="line"><span class="actionscript">    <span class="string">'width=device-width,initial-scale='</span> +</span></span><br><span class="line">    scale +</span><br><span class="line"><span class="actionscript">    <span class="string">', maximum-scale='</span> +</span></span><br><span class="line">    scale +</span><br><span class="line"><span class="actionscript">    <span class="string">', minimum-scale='</span> +</span></span><br><span class="line">    scale +</span><br><span class="line"><span class="actionscript">    <span class="string">', user-scalable=no'</span>;</span></span><br><span class="line"><span class="actionscript">  <span class="comment">// 动态 meta 标签适配</span></span></span><br><span class="line"><span class="javascript">  <span class="built_in">document</span></span></span><br><span class="line"><span class="actionscript">    .querySelector(<span class="string">'meta[name="viewport"]'</span>)</span></span><br><span class="line"><span class="actionscript">    .setAttribute(<span class="string">'content'</span>, content);</span></span><br><span class="line"><span class="actionscript">  <span class="comment">// 基准 font-size 设置</span></span></span><br><span class="line"><span class="javascript">  <span class="built_in">document</span>.documentElement.style.fontSize =</span></span><br><span class="line"><span class="javascript">    <span class="built_in">document</span>.documentElement.clientWidth / <span class="number">75</span> + <span class="string">'px'</span>;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h3 id="CSS-篇"><a href="#CSS-篇" class="headerlink" title="CSS 篇"></a>CSS 篇</h3><h4 id="CSS3-的新特性"><a href="#CSS3-的新特性" class="headerlink" title="CSS3 的新特性"></a>CSS3 的新特性</h4><ul>
<li>transition（过渡动画）、animation（贞动画）、transform（形状变化）</li>
<li>新增选择器（伪类选择器、相邻选择器等）</li>
<li>边框、阴影、滤镜等</li>
<li>弹性布局、栅格布局</li>
</ul>
<blockquote>
<p><a href="https://juejin.im/post/5a0c184c51882531926e4294" target="_blank" rel="noopener">推荐阅读</a></p>
</blockquote>
<h4 id="position-默认值以及默认基于什么定位"><a href="#position-默认值以及默认基于什么定位" class="headerlink" title="position 默认值以及默认基于什么定位"></a>position 默认值以及默认基于什么定位</h4><p>默认值为：static；</p>
<p>定位是基于最近的且 position 值为非 static 的父元素；</p>
<h4 id="水平垂直居中有哪些方法。（至少-3-种）"><a href="#水平垂直居中有哪些方法。（至少-3-种）" class="headerlink" title="水平垂直居中有哪些方法。（至少 3 种）"></a>水平垂直居中有哪些方法。（至少 3 种）</h4><ul>
<li>translate 方法</li>
<li>position + margin 定位</li>
<li>flex 布局</li>
<li>table-ceil 方法</li>
<li>padding 实现</li>
</ul>
<h4 id="清除浮动有哪些方式。"><a href="#清除浮动有哪些方式。" class="headerlink" title="清除浮动有哪些方式。"></a>清除浮动有哪些方式。</h4><ul>
<li>after 伪类（IE 需要设置 zoom: 1）</li>
<li>空 div 元素，设置 css ： <code>clear: both</code></li>
<li>父级形成 BFC 结构，如: <code>overflow: hidden</code></li>
</ul>
<h4 id="BFC-的相关知识考察"><a href="#BFC-的相关知识考察" class="headerlink" title="BFC 的相关知识考察"></a>BFC 的相关知识考察</h4><blockquote>
<p>BFC 提供了一个环境，在这个环境中按照一定规则进行布局不会影响到其它环境中的布局。</p>
</blockquote>
<p><strong>常见问题：</strong></p>
<ul>
<li>高度塌陷</li>
<li>外边距折叠</li>
</ul>
<p><strong>实现方式：</strong></p>
<ul>
<li>浮动元素，float 除 none 以外的值</li>
<li>绝对定位元素，position（absolute，fixed）</li>
<li>display 为以下其中之一的值 inline-block，table-cells，table-captions</li>
<li>overflow 除了 visible 以外的值（hidden，auto，scroll）</li>
<li>……</li>
</ul>
<blockquote>
<p>参考文章： <a href="/2019/05/03/浅谈-BFC/" title="浅谈 BFC">浅谈 BFC</a></p>
</blockquote>
<h4 id="CSS-选择器"><a href="#CSS-选择器" class="headerlink" title="CSS 选择器"></a>CSS 选择器</h4><p>实现以下字体样式效果</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 红 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 白 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 红 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 白 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- ... n 个 p --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span> <span class="attr">class</span>=<span class="string">"center"</span>&gt;</span><span class="comment">&lt;!-- 黄 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 蓝 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 蓝 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 蓝 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!-- ... n 个 p --&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">p</span>&gt;</span><span class="comment">&lt;!-- 绿 --&gt;</span><span class="tag">&lt;/<span class="name">p</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight less"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">div</span> &#123;</span><br><span class="line">  <span class="attribute">background-color</span>: black;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="selector-tag">p</span> &#123;</span><br><span class="line">  <span class="selector-tag">&amp;</span><span class="selector-pseudo">:nth-child(2n)</span> &#123;</span><br><span class="line">    <span class="attribute">color</span>: white;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="selector-tag">&amp;</span><span class="selector-pseudo">:nth-child(2n</span> + <span class="selector-tag">1</span>) &#123;</span><br><span class="line">    <span class="attribute">color</span>: red;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="selector-tag">&amp;</span><span class="selector-class">.center</span> &#123;</span><br><span class="line">    <span class="attribute">color</span>: yellow;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="comment">// 此处得考虑优先级问题</span></span><br><span class="line">  <span class="selector-tag">&amp;</span><span class="selector-class">.center</span> ~ <span class="selector-tag">p</span><span class="selector-pseudo">:not(</span><span class="selector-pseudo">:last-child)</span> &#123;</span><br><span class="line">    <span class="attribute">color</span>: blue;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="selector-tag">&amp;</span><span class="selector-pseudo">:last-child</span> &#123;</span><br><span class="line">    <span class="attribute">color</span>: green;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="JavaScript-篇"><a href="#JavaScript-篇" class="headerlink" title="JavaScript 篇"></a>JavaScript 篇</h3><h4 id="ES6-有哪些新特性"><a href="#ES6-有哪些新特性" class="headerlink" title="ES6+ 有哪些新特性"></a>ES6+ 有哪些新特性</h4><ul>
<li>let, const 变量</li>
<li>模板字符串 “`”</li>
<li>解构赋值 与 扩展运算符（<code>...</code> 运算符）</li>
<li>Promise 与 async</li>
<li>Map、Set</li>
<li>class</li>
<li>Array 的一些原生方法</li>
<li>箭头函数、默认值</li>
<li>…</li>
</ul>
<blockquote>
<p>let 与闭包、解构 undefined 和 null 的值时的默认值问题、class 与原型链、Set 与 除重方法等等</p>
</blockquote>
<h4 id="Promise-all-的实现"><a href="#Promise-all-的实现" class="headerlink" title="Promise.all() 的实现"></a>Promise.all() 的实现</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">PromiseAll</span>(<span class="params">promiseArr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">if</span> (!<span class="built_in">Array</span>.isArray(promiseArr)) &#123;</span><br><span class="line">    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="built_in">TypeError</span>(<span class="string">'You must pass an array'</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">const</span> arrayLen = promiseArr.length;</span><br><span class="line">  <span class="keyword">const</span> resolvedArr = [];</span><br><span class="line">  <span class="keyword">let</span> pos = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">resolve, reject</span>) =&gt;</span> &#123;</span><br><span class="line">    promiseArr.forEach(<span class="function"><span class="params">item</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="built_in">Promise</span>.resolve(item)</span><br><span class="line">      .then(<span class="function"><span class="params">res</span> =&gt;</span> &#123;</span><br><span class="line">        resolvedArr.push(res);</span><br><span class="line">        pos++;</span><br><span class="line">        <span class="keyword">if</span> (pos === arrayLen) &#123;</span><br><span class="line">          resolve(resolvedArr);</span><br><span class="line">        &#125;</span><br><span class="line">      &#125;)</span><br><span class="line">      .catch(<span class="function"><span class="params">e</span> =&gt;</span> &#123;</span><br><span class="line">        reject(e);</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="数组去括号并去重"><a href="#数组去括号并去重" class="headerlink" title="数组去括号并去重"></a>数组去括号并去重</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 试题</span></span><br><span class="line"><span class="keyword">let</span> originArr = [<span class="number">1</span>, <span class="number">2</span>, [<span class="number">2</span>, <span class="number">3</span>], <span class="number">3</span>, [<span class="number">2</span>, [<span class="number">3</span>, <span class="number">0</span>]], <span class="number">4</span>, [[[<span class="number">5</span>]]]]</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 实现的方法:</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">formatArr</span>(<span class="params">originArr</span>) </span>&#123;</span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">flattenDeep</span>(<span class="params">arr</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">let</span> resArr = [];</span><br><span class="line">    <span class="keyword">if</span> (<span class="built_in">Array</span>.isArray(arr)) &#123;</span><br><span class="line">      resArr = arr.reduce(<span class="function">(<span class="params">a,b</span>)=&gt;</span>[...a, ...flattenDeep(b)], resArr);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      resArr.push(arr);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> resArr;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">const</span> flatArr = flattenDeep(originArr);</span><br><span class="line">  <span class="keyword">return</span> [...new <span class="built_in">Set</span>(flatArr)];</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> testArr = [<span class="number">1</span>, [[<span class="number">2</span>], [<span class="number">3</span>, [<span class="number">4</span>, <span class="number">5</span>]], <span class="number">5</span>]];</span><br><span class="line"><span class="built_in">console</span>.log(formatArr(testArr));</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 简单方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">formatArr</span>(<span class="params">originArr</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">const</span> flatArr = originArr.toString().split(<span class="string">','</span>);</span><br><span class="line">  <span class="keyword">const</span> filteredArr = [...new <span class="built_in">Set</span>(flatArr)];</span><br><span class="line">  <span class="keyword">return</span> filteredArr.map(<span class="function"><span class="params">n</span> =&gt;</span> <span class="built_in">Number</span>(n));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="This-指向问题"><a href="#This-指向问题" class="headerlink" title="This 指向问题"></a>This 指向问题</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> obj = &#123;</span><br><span class="line">  b: <span class="number">1</span>,</span><br><span class="line">  a: <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">      <span class="built_in">console</span>.log(<span class="keyword">this</span>.b)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">obj.a()</span><br><span class="line"><span class="comment">// 输出 undefined</span></span><br></pre></td></tr></table></figure>
<blockquote>
<p>参考文章： <a href="/2019/05/19/深入了解-this/" title="深入了解 this">深入了解 this</a></p>
</blockquote>
<h4 id="以下代码依次输出的结果"><a href="#以下代码依次输出的结果" class="headerlink" title="以下代码依次输出的结果"></a>以下代码依次输出的结果</h4><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">async1</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'as1'</span>)</span><br><span class="line">  <span class="keyword">await</span> async2()</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'end as1'</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">async2</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'as2'</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'start'</span>)</span><br><span class="line"></span><br><span class="line">async1(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line">setTimeout(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'setTimeout'</span>)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> <span class="built_in">Promise</span>(<span class="function">(<span class="params">rs, rj</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'promise'</span>)</span><br><span class="line">  rs()</span><br><span class="line">&#125;).then(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">'then'</span>)</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'end'</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">start</span><br><span class="line">as1</span><br><span class="line">as2</span><br><span class="line">promise</span><br><span class="line">end</span><br><span class="line">end as1</span><br><span class="line">then</span><br><span class="line">setTimeout</span><br></pre></td></tr></table></figure>
<h3 id="HTTP-篇"><a href="#HTTP-篇" class="headerlink" title="HTTP 篇"></a>HTTP 篇</h3><h4 id="常用的-HTTP-方法有哪些"><a href="#常用的-HTTP-方法有哪些" class="headerlink" title="常用的 HTTP 方法有哪些"></a>常用的 HTTP 方法有哪些</h4><ul>
<li>GET：用于请求访问已经被 URI 识别的资源，可以通过 URL 传参给服务器</li>
<li>POST：用于传输信息给服务器,主要功能 GET 类似，但一般推荐使用 POST 方式</li>
<li>PUT：传输文件，报文主体中包含文件内容，保存到对应的 URI 位置</li>
<li>HEAD：获得报文首部，与 GET 方法类似，只是不返回报文主体，一般用于验证 URI 是否有效</li>
<li>DELETE：删除文件，与 PUT 方法相反，删除对应 URI 位置的文件</li>
<li>OPTIONS：查询对应 URI 支持的 HTTP 方法</li>
</ul>
<h4 id="GET-和-POST-的区别"><a href="#GET-和-POST-的区别" class="headerlink" title="GET 和 POST 的区别"></a>GET 和 POST 的区别</h4><ul>
<li>GET 重点从服务器上获取资源，POST 重点向服务器发送数据</li>
<li>GET 传输的数据量小，因为受 URL 长度限制，但效率较高；POST 可以传输大量数据，所以上传文件时只能用 POST 方式；</li>
<li>GET 是不安全的，因为 URL 是可见的，可能会泄露私密信息，如密码等；<br>POST 较 GET 安全性较高；</li>
</ul>
<h4 id="请求报文和响应报文"><a href="#请求报文和响应报文" class="headerlink" title="请求报文和响应报文"></a>请求报文和响应报文</h4><p><strong>a. 请求报文包含三部分：</strong></p>
<ul>
<li>请求行：包含请求方法、URI、HTTP 版本信息</li>
<li>请求首部字段</li>
<li>请求内容实体</li>
</ul>
<p><strong>b. 响应报文包含三部分：</strong></p>
<ul>
<li>状态行：包含 HTTP 版本、状态码、状态码的原因短语</li>
<li>响应首部字段</li>
<li>响应内容实体</li>
</ul>
<h4 id="常见的状态码"><a href="#常见的状态码" class="headerlink" title="常见的状态码"></a>常见的状态码</h4><ul>
<li>200：表示请求已成功，请求所希望的响应头或数据体将随此响应返回。</li>
<li>301：永久重定向，资源已永久分配新 URI。</li>
<li>302：临时重定向，资源已临时分配新 URI。</li>
<li>304：自从上次请求后，请求的网页未修改过。服务器返回此响应时，不会返回网页内容。</li>
<li>307：临时重定向，POST 不会变成 GET。</li>
<li>401：需要通过 HTTP 认证，或认证失败。</li>
<li>403：表示对请求资源的访问被服务器拒绝了。</li>
<li>404：表示服务器找不到你请求的资源。</li>
<li>500：表示服务器执行请求的时候出错了。</li>
<li>503：表示服务器超负载或正停机维护，无法处理请求。</li>
</ul>
<h4 id="强缓存和协商缓存"><a href="#强缓存和协商缓存" class="headerlink" title="强缓存和协商缓存"></a>强缓存和协商缓存</h4><p><strong>a. 强缓存相关的字段：</strong></p>
<ul>
<li>expires</li>
<li>cache-control：max-age=number</li>
</ul>
<p><strong>b. 协商缓存相关的字段：</strong></p>
<ul>
<li>Last-Modified/If-Modified-Since</li>
<li>Etag/If-None-Match</li>
</ul>
<p><img data-src="/images/http-cache.png" alt></p>
<h3 id="性能优化"><a href="#性能优化" class="headerlink" title="性能优化"></a>性能优化</h3><h4 id="HTML"><a href="#HTML" class="headerlink" title="HTML"></a>HTML</h4><ul>
<li>不要使用空 src 的 <code>image</code> 标签</li>
<li>减少 iframe 的数量，其开销高，会阻塞 onload 事件，同域会抢资源</li>
<li>减少不必要的 DOM 元素</li>
<li>图片懒加载</li>
<li>使用 CDN 的资源</li>
<li>css 样式放在顶部 header，js 放在 body 最后面</li>
</ul>
<h4 id="CSS"><a href="#CSS" class="headerlink" title="CSS"></a>CSS</h4><ul>
<li>能使用 base64 的尽量使用 base64</li>
<li>背景图加载</li>
<li>尽量不使用 @import 语法</li>
</ul>
<h4 id="JavaScript"><a href="#JavaScript" class="headerlink" title="JavaScript"></a>JavaScript</h4><ul>
<li>减少 DOM 访问</li>
<li>多次修改统一节点时使用 documentFragment 文档片段来做中间拼接处理</li>
<li>减少获取 clientHeight 等信息的次数，会造成反复重绘</li>
<li>合理添加事件监听函数</li>
</ul>
<h3 id="其它"><a href="#其它" class="headerlink" title="其它"></a>其它</h3><h4 id="短链接的生成思路"><a href="#短链接的生成思路" class="headerlink" title="短链接的生成思路"></a>短链接的生成思路</h4><p>一般链接的特点：不考虑 query 字段，一般就只有 26 个英文字母，而短链接的特点是含有 ([a-z][a-z][0-9])，因此一个粗略的想法就是将 26 进制转化成 62 进制，因此将对应算法写出来基本上就算是答道点子上了。</p>
<p>算法的大致思路为： 26 进制 -&gt; 10 进制 -&gt; 62 进制</p>
<h3 id="参考文档"><a href="#参考文档" class="headerlink" title="参考文档"></a>参考文档</h3><ul>
<li><a href="https://www.cnblogs.com/FunkyEric/p/8979227.html" target="_blank" rel="noopener">前端面试问题</a></li>
</ul>

    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>蔡胤
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://monocy.gitee.io/2020/01/27/前端面试题大全/" title="前端面试题大全">https://monocy.gitee.io/2020/01/27/前端面试题大全/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/面试题/" rel="tag"><i class="fa fa-tag"></i> 面试题</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/01/19/Mac-指令学习/" rel="prev" title="Mac 指令学习">
      <i class="fa fa-chevron-left"></i> Mac 指令学习
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/03/04/npx-的用途/" rel="next" title="npx 的用途">
      npx 的用途 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTML-篇"><span class="nav-number">2.</span> <span class="nav-text">HTML 篇</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#H5-有哪些新特性"><span class="nav-number">2.1.</span> <span class="nav-text">H5 有哪些新特性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#webStorage-和-Cookie-的区别以及各自的优缺点"><span class="nav-number">2.2.</span> <span class="nav-text">webStorage 和 Cookie 的区别以及各自的优缺点</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#svg-与-canvas"><span class="nav-number">2.3.</span> <span class="nav-text">svg 与 canvas</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#移动端页面适配方案"><span class="nav-number">2.4.</span> <span class="nav-text">移动端页面适配方案</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#CSS-篇"><span class="nav-number">3.</span> <span class="nav-text">CSS 篇</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#CSS3-的新特性"><span class="nav-number">3.1.</span> <span class="nav-text">CSS3 的新特性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#position-默认值以及默认基于什么定位"><span class="nav-number">3.2.</span> <span class="nav-text">position 默认值以及默认基于什么定位</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#水平垂直居中有哪些方法。（至少-3-种）"><span class="nav-number">3.3.</span> <span class="nav-text">水平垂直居中有哪些方法。（至少 3 种）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#清除浮动有哪些方式。"><span class="nav-number">3.4.</span> <span class="nav-text">清除浮动有哪些方式。</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#BFC-的相关知识考察"><span class="nav-number">3.5.</span> <span class="nav-text">BFC 的相关知识考察</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#CSS-选择器"><span class="nav-number">3.6.</span> <span class="nav-text">CSS 选择器</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#JavaScript-篇"><span class="nav-number">4.</span> <span class="nav-text">JavaScript 篇</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#ES6-有哪些新特性"><span class="nav-number">4.1.</span> <span class="nav-text">ES6+ 有哪些新特性</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Promise-all-的实现"><span class="nav-number">4.2.</span> <span class="nav-text">Promise.all() 的实现</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#数组去括号并去重"><span class="nav-number">4.3.</span> <span class="nav-text">数组去括号并去重</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#This-指向问题"><span class="nav-number">4.4.</span> <span class="nav-text">This 指向问题</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#以下代码依次输出的结果"><span class="nav-number">4.5.</span> <span class="nav-text">以下代码依次输出的结果</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTTP-篇"><span class="nav-number">5.</span> <span class="nav-text">HTTP 篇</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常用的-HTTP-方法有哪些"><span class="nav-number">5.1.</span> <span class="nav-text">常用的 HTTP 方法有哪些</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#GET-和-POST-的区别"><span class="nav-number">5.2.</span> <span class="nav-text">GET 和 POST 的区别</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#请求报文和响应报文"><span class="nav-number">5.3.</span> <span class="nav-text">请求报文和响应报文</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#常见的状态码"><span class="nav-number">5.4.</span> <span class="nav-text">常见的状态码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#强缓存和协商缓存"><span class="nav-number">5.5.</span> <span class="nav-text">强缓存和协商缓存</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#性能优化"><span class="nav-number">6.</span> <span class="nav-text">性能优化</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#HTML"><span class="nav-number">6.1.</span> <span class="nav-text">HTML</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#CSS"><span class="nav-number">6.2.</span> <span class="nav-text">CSS</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#JavaScript"><span class="nav-number">6.3.</span> <span class="nav-text">JavaScript</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#其它"><span class="nav-number">7.</span> <span class="nav-text">其它</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#短链接的生成思路"><span class="nav-number">7.1.</span> <span class="nav-text">短链接的生成思路</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#参考文档"><span class="nav-number">8.</span> <span class="nav-text">参考文档</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="蔡胤"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">蔡胤</p>
  <div class="site-description" itemprop="description">Just do IT!</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">61</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">15</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/kazehaiya" title="GitHub → https://github.com/kazehaiya" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:c763416559@163.com" title="Mail → mailto:c763416559@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/Nora_Monocy" title="Weibo → https://weibo.com/Nora_Monocy" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i></a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      友情链接
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="http://liujinkai.com/" title="http://liujinkai.com/" rel="noopener" target="_blank">凯凯刘</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://weekly.75team.com/" title="https://weekly.75team.com/" rel="noopener" target="_blank">奇舞周刊</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://75.team/post/list" title="https://75.team/post/list" rel="noopener" target="_blank">奇舞团博客</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://tech.meituan.com/" title="https://tech.meituan.com/" rel="noopener" target="_blank">美团技术团队</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://tech.youzan.com/" title="https://tech.youzan.com/" rel="noopener" target="_blank">有赞技术团队</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://kalacloud.com" title="https://kalacloud.com" rel="noopener" target="_blank">卡拉云</a>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        
  <div class="beian"><a href="https://beian.miit.gov.cn" rel="noopener" target="_blank">京ICP备2020036147号-1 </a>
      <img src="/images/beian.png" style="display: inline-block;"><a href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=42011702000651" rel="noopener" target="_blank">鄂公网安备 42011702000651 号 </a>
  </div>

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-dragon"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">蔡胤</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">101k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:32</span>
</div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/theme-next/theme-next-pjax@0/pjax.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/medium-zoom@1/dist/medium-zoom.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>
  <script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '#page-configurations',
    '.content-wrap',
    '.post-toc-wrap',
    '.languages',
    '#pjax'
  ],
  switches: {
    '.post-toc-wrap': Pjax.switches.innerHTML
  },
  analytics: false,
  cacheBust: false,
  scrollTo : !CONFIG.bookmark.enable
});

window.addEventListener('pjax:success', () => {
  document.querySelectorAll('script[data-pjax], script#page-configurations, #pjax script').forEach(element => {
    var code = element.text || element.textContent || element.innerHTML || '';
    var parent = element.parentNode;
    parent.removeChild(element);
    var script = document.createElement('script');
    if (element.id) {
      script.id = element.id;
    }
    if (element.className) {
      script.className = element.className;
    }
    if (element.type) {
      script.type = element.type;
    }
    if (element.src) {
      script.src = element.src;
      // Force synchronous loading of peripheral JS.
      script.async = false;
    }
    if (element.dataset.pjax !== undefined) {
      script.dataset.pjax = '';
    }
    if (code !== '') {
      script.appendChild(document.createTextNode(code));
    }
    parent.appendChild(script);
  });
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  NexT.utils.updateSidebarPosition();
});
</script>




  




  <script src="/js/local-search.js"></script>












    <div id="pjax">
  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : true,
      notify     : true,
      appId      : 'GkgJm97N3UFm2mRb1eFcP2dn-gzGzoHsz',
      appKey     : 'kJ8tYUUkX4ifhWha8rjnxWS8',
      placeholder: "请不要吝惜你的笔头，来说点什么吧！",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : false,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : true,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

    </div>
<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/Epsilon2.1.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true,"scale":0.5},"react":{"opacity":0.7},"log":false});</script></body>
</html>
